﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCDropDownList.Models;
using System.Globalization;

namespace MVCDropDownList.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            MVCDropDownList.Models.Calendar calendar = new MVCDropDownList.Models.Calendar();
            calendar = GetMonths(calendar);
            return View(calendar);
        }

        [HttpPost]
        public ActionResult Index(MVCDropDownList.Models.Calendar calendar)
        {
            //if (calendar.btnClicked == "Save")
            {
                ViewBag.page = "Index";
                calendar = GetMonths(calendar);
                //calendar.SelctedMonth = calendar.Month.ToString();
            }
            return View(calendar);
        }

        private static MVCDropDownList.Models.Calendar GetMonths(MVCDropDownList.Models.Calendar calendar)
        {
            //calendar = new MVCDropDownList.Models.Calendar();
            List<SelectListItem> months = new List<SelectListItem>();
            for (int monthNo = 1; monthNo <= 12; monthNo++)
                months.Add(new SelectListItem { Text = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(monthNo), Value = monthNo.ToString() });
            calendar.Months = months;
            return calendar;
        }        
    }
}
